package com.hao.wms.query;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

public class QueryObject {
	private Integer currentPage = 1;
	private Integer pageSize = 10;
	private List<String> conditions = new ArrayList<>();
	private List<Object> params = new ArrayList<>();
	private boolean isInit;

	public void customerQuery() {

	}

	public void init() {
		if (!isInit) {
			customerQuery();
			isInit = true;
		}

	}

	public void addQuery(String condition, Object... params) {
		conditions.add("("+condition+")");
		this.params.addAll(Arrays.asList(params));
	}

	public String getQuery() {
		init();
		if (conditions.size() > 0) {
			StringBuilder where = new StringBuilder(200).append(" WHERE ")
					.append(StringUtils.join(conditions, " AND "));
			return where.toString();
		}
		return "";
	}

	public List<Object> getParams() {
		init();
		return this.params;
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPgae) {
		this.currentPage = currentPgae;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public boolean hasLength(String str){
		return str!=null&&!"".equals(str.trim());
	}

}
